package com.frxuexi.park

import com.frxuexi.base.http.ApiService
import com.frxuexi.base.mvi.BaseViewModel
import com.frxuexi.base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class ParkViewModel @Inject constructor(val apiService: ApiService) : BaseViewModel<ParkIntent>() {
    override fun handleIntent(it: ParkIntent) {
        when (it) {
            is ParkIntent.getParkByType ->
//                pagerRequest { ParkDataSource(apiService,it.type,"类型") }
                httpRequest(apiService.getParkByType(it.type))

            is ParkIntent.getParkByStatus ->
                /* pagerRequest {
                 ParkDataSource(apiService,it.status,"状态")
             }*/
                httpRequest(apiService.getParkByStatus(it.status))

            is ParkIntent.getParkByArea ->
//                pagerRequest { ParkDataSource(apiService,it.area,"区域") }
                httpRequest(apiService.getParkByArea(it.area.toInt()))

            is ParkIntent.getParkByUid ->
//                pagerRequest { ParkDataSource(apiService,it.uid,"用户") }
                httpRequest(apiService.getParkByUid(it.uid.toInt()),RequestType.ITEM)

            is ParkIntent.getParkByCarNo ->
//                pagerRequest { ParkDataSource(apiService,it.carNo,"车牌号") }
                httpRequest(apiService.getParkByCarNo(it.carNo),RequestType.ITEM)

            is ParkIntent.addPark -> httpRequest(
                apiService.addPark(toBody(it.item)),
                RequestType.ADD
            )

            is ParkIntent.updatePark -> httpRequest(
                apiService.updatePark(it.id, toBody(it.item)),
                RequestType.UPDATE
            )

            is ParkIntent.deletePark -> httpRequest(
                apiService.deletePark(it.id),
                RequestType.DELETE
            )

            is ParkIntent.getParkById -> httpRequest(apiService.getParkById(it.id))
        }
    }
}